package com.edu.test;


import com.edu.bean.*;
import com.edu.mapper.DepartMapper;
import com.edu.mapper.EmpMapper;
import com.edu.mapper.StudentMapper;
import com.edu.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * @Author:mx
 * @Date:2025/9/30-8:50:18
 */
public class MyTest02 {

    SqlSession session = null;

    @Before
    public void init() throws Exception{
        String path = "mybatis-config.xml";
        InputStream ins = Resources.getResourceAsStream(path);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(ins);
        session = sqlSessionFactory.openSession();
    }


    @Test
    public void test01(){
        UserMapper userMapper = session.getMapper(UserMapper.class);
        User user = userMapper.selectUserById(1);
        System.out.println(user);
        for (Bill bill : user.getBillList()) {
            System.out.println(bill);
        }
    }

    @Test
    public void test02(){
        UserMapper userMapper = session.getMapper(UserMapper.class);
        List<User> userList = userMapper.selectAll();
        for (User user : userList) {
            System.out.println(user);
            System.out.println("该用户的账单");
            for (Bill bill : user.getBillList()) {
                System.out.println(bill);
            }
            System.out.println("-------------------------");
        }
    }


    @Test
    public void test03(){
        UserMapper userMapper = session.getMapper(UserMapper.class);
        User user = userMapper.selectUserById2(11);
//        System.out.println(user);
        System.out.println("-----------------");
        System.out.println(user.getBillList());
    }

    @Test
    public void test04(){
        DepartMapper departMapper = session.getMapper(DepartMapper.class);
        Depart depart = departMapper.selectDepartEmpById(1);
        System.out.println("部门信息");
        System.out.println(depart);
        for (Emp emp : depart.getEmpList()) {
            System.out.println("员工信息");
            System.out.println(emp);
            System.out.println("员工所在部门的信息");
            System.out.println(emp.getMyDepart());
            System.out.println("------");
            System.out.println(emp.getMyDepart().getEmpList());
        }
    }

    @Test
    public void test05(){
        DepartMapper departMapper = session.getMapper(DepartMapper.class);
        for (Depart depart : departMapper.selectAll()) {
            System.out.println(depart);
            System.out.println(depart.getEmpList());
            System.out.println("----");
        }
    }


    @Test
    public void test06(){
        DepartMapper departMapper = session.getMapper(DepartMapper.class);
        Depart depart = departMapper.selectDepartById2(1);
        System.out.println("部门信息");
        System.out.println(depart);
        for (Emp emp : depart.getEmpList()) {
            System.out.println("员工信息");
            System.out.println(emp);
            System.out.println("员工所在部门的信息");
            System.out.println(emp.getMyDepart());

            System.out.println(emp.getMyDepart().getEmpList());
            System.out.println(emp.getMyDepart().getEmpList().get(0).getMyDepart());
            System.out.println("------");
        }
    }


}
